package com.lx.order.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lx.order.entities.UserOrder;
import com.lx.order.mapper.OrderMapper;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author dh
 * @since 2024-10-23
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, UserOrder> implements IOrderService {

    @Resource
    private OrderMapper orderMapper;
    @Resource
    RocketMQTemplate rocketMQTemplate;

    @Override
    public boolean saveOrder(UserOrder order) {
        orderMapper.insert(order);
        return false;
    }

    @Override
    public boolean sendMessage(Long orderId) {
        Message<Long> message = MessageBuilder.withPayload(orderId).build();
        rocketMQTemplate.sendMessageInTransaction(
                "order-topic",message
                 , null);
        return false;
    }
}
